<?php
namespace Home\Controller;
use Think\Controller;

class ArticlelistController extends  BaseController
{
	public function index(){
		
		//分页
		$page = intval($GLOBALS['request']['page']);
		if($page==0)
			$page = 1;
		
		$root = get_baseroot();
		
		if((int)$GLOBALS['request']['cate_id'] > 0)
			$cate_id =(int)$GLOBALS['request']['cate_id'];
		else
			$cate_id =intval($GLOBALS['m_config']['article_cate_id']);
		$cate_id = 5;
		$cate = $GLOBALS['db']->getRow("SELECT * FROM ".DB_PREFIX."article_cate WHERE id=".$cate_id);
		//var_dump($cate_id);
		//exit;
		//分页
		$limit = (($page-1)*app_conf("PAGE_SIZE")).",".app_conf("PAGE_SIZE");
		
		$sql = "select id,title from ".DB_PREFIX."article where is_effect = 1 and is_delete = 0 and cate_id = ".$cate_id." order by sort DESC ";
		$sql.=" limit ".$limit;
		
		$sql_count = "select count(*) from ".DB_PREFIX."article where is_effect = 1 and is_delete = 0 and cate_id = ".$cate_id;
		

		$count = $GLOBALS['db']->getOne($sql_count);
		$list = array();
		if($count >0)
			$list = $GLOBALS['db']->getAll($sql);
	
	
						
		$root['page'] = array("page"=>$page,"page_total"=>ceil($count/app_conf("PAGE_SIZE")),"page_size"=>app_conf("PAGE_SIZE"));	
		
		$root['response_code'] = 1;
		$root['cate'] = $cate;
		$root['list'] = $list;
		$root['program_title'] = $cate['title'];
		//output($root);
        $root['act'] = CONTROLLER_NAME;
        $root['hide_back'] = 1 ;
        $this->assign('data',$root);
        $this->display();
	}
}
?>
